<script setup lang="ts">
import { skillNewsPage } from "~/api/headlines";

useSeoMeta({
  title: "技能头条 - 技能猴子",
  ogTitle: "技能头条 - 技能猴子",
  description: "技能猴子，找技能服务，我喜欢和技能人才直接聊",
  ogDescription: "技能猴子，找技能服务，我喜欢和技能人才直接聊",
});

const router = useRouter();
const toDetails = (id: number) => {
  router.push({
    path: "/newDetails",
    query: {
      id,
    },
  });
};

onMounted(() => {
  getList();
});

const params = ref({
  pageNum: 1,
  pageSize: 10,
});
const total = ref(0);
const list = ref([]);
const loading = ref(false);
const getList = async () => {
  try {
    loading.value = true;
    const data = await skillNewsPage(params.value);
    total.value = data.total;
    list.value = data.rows;
  } catch (e) {
    console.log(e);
  } finally {
    loading.value = false;
  }
};
//
const currentChange = (pageNum: number) => {
  params.value.pageNum = pageNum;
  getList();
};
</script>

<template>
  <div class="body">
    <BaseHeaderMenuWhite bg-color="white" />
    <div class="news-page">
      <p class="page-title">技能头条</p>
      <div class="new-list" v-loading="loading" custom-class="new-list-loading">
        <div v-for="item of list" :key="item.id" class="item" @click="toDetails(item.id)">
          <div class="new-title">
            <span v-if="item.setTop">置顶</span>
            <h4>
              <b>{{ item.title }}</b> <d>{{ item.createTime }}</d>
            </h4>
          </div>
          <p v-html="item.content"></p>
        </div>
        <div class="pagination">
          <el-pagination
            layout="prev, pager, next"
            :total="total"
            @current-change="currentChange"
          />
        </div>
      </div>
    </div>
  </div>
  <BaseFooter />
</template>

<style scoped lang="scss">
.body {
  background: #f9f9f9;
  min-height: 100vh;
  padding-bottom: 40px;
}

.news-page {
  padding-top: 80px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
  box-sizing: border-box;
}

.page-title {
  padding-top: 32px;
  font-size: 20px;
  color: #191e28;
  font-weight: 600;
  padding-bottom: 16px;
}

.new-list {
  background: #ffffff;
  box-shadow: 0px 0px 16px 0px rgba(11, 13, 18, 0.06);
  border-radius: 16px;
  border: 1px solid rgba(25, 30, 40, 0.08);
  padding: 4px 24px 24px;
  box-sizing: border-box;
  min-height: 300px;
}

.item {
  width: 100%;
  padding: 20px 0;
  border-bottom: 1px solid rgba(25, 30, 40, 0.08);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  cursor: pointer;

  &:hover {
    background-color: rgba(29, 191, 115, 0.02);
  }

  .new-title {
    width: 100%;
    overflow: hidden;
    margin-bottom: 12px;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;

    span {
      flex-shrink: 0;
      font-size: 12px;
      color: #ff8c1d;
      padding: 2px 8px;
      background: rgba(255, 140, 29, 0.08);
      border-radius: 4px;
      white-space: nowrap;
    }

    h4 {
      flex: 1;
      font-size: 16px;
      color: #191e28;
      font-weight: bold;
      display: flex;
      flex-direction: column;
      gap: 4px;
      margin: 0;

      b {
        display: block;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        line-height: 1.4;
      }

      d {
        color: rgba(25, 30, 40, 0.36);
        font-size: 12px;
        font-weight: normal;
        align-self: flex-end;
      }
    }
  }

  p {
    color: rgba(25, 30, 40, 0.6);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    line-height: 1.5;
    margin: 0;
  }
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 16px;
}

// 平板适配 (768px - 1024px)
@media (max-width: 1024px) {
  .news-page {
    padding-left: 20px;
    padding-right: 20px;
  }

  .new-list {
    padding: 4px 20px 20px;
  }

  .item .new-title h4 {
    font-size: 15px;

    d {
      font-size: 11px;
    }
  }
}

// 移动端适配 (最大768px)
@media (max-width: 768px) {
  .news-page {
    padding-top: 60px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .page-title {
    padding-top: 20px;
    font-size: 18px;
    padding-bottom: 12px;
  }

  .new-list {
    border-radius: 12px;
    padding: 4px 16px 16px;
  }

  .item {
    padding: 16px 0;

    .new-title {
      flex-direction: column;
      gap: 8px;

      span {
        align-self: flex-start;
        font-size: 11px;
        padding: 1px 6px;
      }

      h4 {
        font-size: 14px;

        b {
          white-space: normal;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
        }

        d {
          font-size: 11px;
          align-self: flex-start;
          margin-top: 4px;
        }
      }
    }

    p {
      font-size: 14px;
      -webkit-line-clamp: 2;
      line-clamp: 2;
    }
  }

  .pagination {
    padding-top: 12px;
  }
}

// 小屏手机适配 (最大480px)
@media (max-width: 480px) {
  .news-page {
    padding-left: 12px;
    padding-right: 12px;
  }

  .page-title {
    font-size: 16px;
    padding-top: 16px;
  }

  .new-list {
    padding: 4px 12px 12px;
    border-radius: 8px;
  }

  .item {
    padding: 12px 0;

    .new-title h4 {
      font-size: 13px;

      d {
        font-size: 10px;
      }
    }

    p {
      font-size: 13px;
    }
  }
}

// 超大屏幕适配 (大于1200px)
@media (min-width: 1200px) {
  .news-page {
    max-width: 1200px;
  }
}
</style>
<style lang="scss" scoped>
.news-page .el-pagination button:disabled {
  background: none;
}

.news-page .el-pagination button.is-first {
  margin-right: 6px;
}

.news-page .el-pagination button.is-last {
  background: none;
  &:hover {
    font-weight: bold;
    color: #191e28;
  }
}

.news-page .el-pager li {
  background: none;
  width: 36px;
  height: 36px;
  margin-right: 6px;
  &:hover {
    font-weight: bold;
    color: #191e28;
  }
}

.news-page .el-pager li.is-active {
  background: #fff;
  box-shadow: 0 0 16px 0 rgba(11, 13, 18, 0.06);
  border-radius: 8px;
  border: 1px solid rgba(25, 30, 40, 0.08);
  color: #191e28;
}

.news-page .el-checkbox.el-checkbox--large .el-checkbox__inner {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid rgba(25, 30, 40, 0.08);
  display: flex;
}

.news-page .el-checkbox__input.is-checked .el-checkbox__inner {
  background: #1dbf73;
  border: 1px solid #1dbf73;
}

.news-page .el-checkbox__inner:after {
  top: 3px;
  left: 7px;
}

// 移动端分页样式优化
@media (max-width: 768px) {
  .news-page .el-pager li {
    width: 32px;
    height: 32px;
    margin-right: 4px;
    font-size: 14px;
  }

  .news-page .el-pagination button {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .news-page .el-pagination button.is-first {
    margin-right: 4px;
  }
}

@media (max-width: 480px) {
  .news-page .el-pager li {
    width: 28px;
    height: 28px;
    margin-right: 2px;
    font-size: 12px;
  }

  .news-page .el-pagination button {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .news-page .el-pagination button.is-first {
    margin-right: 2px;
  }
}
</style>

<style lang="scss">
.new-list {
  img {
    max-width: 100%;
    max-height: 200px;
    object-fit: cover;
  }
  .new-list-loading {
    color: #1dbf73;
  }
}
</style>
